<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>保单添加</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="/plugins/layui/css/layui.css" media="all" />
	<style type="text/css">
		.layui-form{
			padding: 20px ;
		}
		.layui-form-item {
			width: 33.333%;
			float: left;
			margin-right: 0;
		}

		@media (max-width: 1240px) {
			.layui-form-item .layui-inline {
				width: 100%;
				float: none;
			}
		}
	</style>
</head>
<body class="childrenBody">
	<form class="layui-form layui-form-pane">
		<div class="layui-form-item">
			    <label class="layui-form-label">保险公司</label>
			    <div class="layui-input-block">
			      <select name="companyType" lay-verify="required" id="companyType">
					  <option value="">--请选择保险公司--</option>
					  <option value="1">中国人保</option>
					  <option value="2">中国人寿</option>
					  <option value="3">中国平安</option>
					  <option value="4">太平洋保险</option>
					  <option value="5">中国太平</option>
					  <option value="6">友邦保险</option>
					  <option value="7">新华保险</option>
					  <option value="8">泰康保险</option>
					  <option value="9">阳光保险</option>
					  <option value="10">大地车险</option>
					  <option value="11">天安车险</option>
					  <option value="12">安邦车险</option>
					  <option value="13">华泰车险</option>
					  <option value="14">安盛天平车险</option>
					  <option value="15">中银车险</option>
					  <option value="16">永诚车险</option>
			      </select>
			    </div>
	  	</div>
		<div class="layui-form-item">
			<label class="layui-form-label">保单号</label>
			<div class="layui-input-block">
				<input type="text" class="layui-input" lay-verify="required" name="code" placeholder="请输入保单号">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">客户</label>
			<div class="layui-input-inline">
				<select name="customerId" lay-verify="required" lay-filter="test" lay-search id="customerId">
				 	<option value="">--请选择客户--</option>
				</select>
			</div>
			 <div class="layui-form-mid layui-word-aux">请根据手机号码或姓名检索</div>
		
		</div>
		
		<div class="layui-form-item">
			<label class="layui-form-label">投保车辆</label>
			<div class="layui-input-block">
				<select name="customerCarId" lay-verify="required" id="carInfoId">
				 	<option value="">--请选择车辆信息--</option>
				</select> 
			</div>
		
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">投保日期</label>
			<div class="layui-input-inline">
				<input type="text" id="test1"  class="layui-input" lay-verify="required" name="expiryTime" placeholder="请选择保单生效日期">
			</div>
			<div class="layui-form-mid layui-word-aux"><span> 0时起  至 </span><span id="end_time"></span></div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">投保金额</label>
			<div class="layui-input-block">
				<input type="text" class="layui-input" name="policyMoney" placeholder="请输入投保金额">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">礼包金额</label>
			<div class="layui-input-block">
				<input type="text" class="layui-input" name="returnMoney" placeholder="请输入礼包金额">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">投保人</label>
			<div class="layui-input-block">
				<input type="text" class="layui-input" name="policyName" placeholder="投保人">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">投保人手机号码</label>
			<div class="layui-input-block">
				<input type="text" class="layui-input" name="policyPhone" placeholder="投保人手机号码">
			</div>
		</div>
		
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit="" lay-filter="addPolicys">立即提交</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
		    </div>
		</div>
	</form>
	<script type="text/javascript" src="/js/jquery-1.11.2.min.js"></script>
	<script type="text/javascript" src="/plugins/layui/layui.js"></script>
<!-- 	<script type="text/javascript" src="/js/user/newsAdd.js"></script> -->
	
	<script type="text/javascript">
	

 
	
	layui.config({
		base : "/js/admin/"
	}).extend({
	    $tool: 'tool'
	}).use(['form','layer','jquery','layedit','laydate','$tool'],function(){
		var form = layui.form,
			layer = parent.layer === undefined ? layui.layer : parent.layer,
			laypage = layui.laypage,
			layedit = layui.layedit,
			laydate = layui.laydate,
			$ = layui.jquery;
		   	$tool = layui.$tool;
		
		   	Date.prototype.addYears = function (y) {  
			    var m = this.getMonth();  
			    this.setFullYear(this.getFullYear() + y);  
			    if (m < this.getMonth()) {  
			        this.setDate(0);  
			    }  
			}; 
			
		    laydate.render({
			    elem: '#test1', //指定元素
			    done: 
			    	function(value, date){
			    	var selectedDate=new Date(date.year,date.month-1,date.date);
			    	 var m = selectedDate.getMonth();
			    	 selectedDate.setFullYear(selectedDate.getFullYear() + 1);  
					    if (m < selectedDate.getMonth()) {  
					    	selectedDate.setDate(0);  
					    }  
			    	 var text=$tool.formatDate(selectedDate);
			    	 $("#end_time").html(text+" 24时止")
			    	 form.render();  
			    	}
			});
		   	
			  var membersList;
			  $.ajax({
		          type : "GET",
		          url: '/storeMember/getAllStoreMembers',
		          dataType:'json',
		       	  async:false,
		          success: function(data){
		          	var list=data.data;
		          	membersList=list;
		          	var html='';
		              for(var i=0;i<list.length;i++){	
		                  html += "<option value='"+list[i].id+"'>"+list[i].phone+"   "+list[i].name+"</option>"
		              }
		              $("#customerId").append(html);
		              form.render();
		          }
		      }); 
			  form.on('select(test)', function(data){
				  if(data.value!=''){
					  $.ajax({
				          type : "GET",
				          url: '/storeMemberCar/getCarsByStoreMember/'+data.value,
				          dataType:'json',
				       	  async:false,
				          success: function(data){
				          	var list=data.data;
				          	membersList=list;
				          	var html='<option value="">--请选择车辆信息--</option>';
				              for(var i=0;i<list.length;i++){	
				                  html += "<option value='"+list[i].id+"'>"+list[i].plateNumber+"   "+list[i].carInfo+"</option>"
				              }
				              
				              $("#carInfoId").html(html);
				              form.render();
				          }
				      });
				  }
	            	
	          }); 
		  
			
		//创建一个编辑器
	 	form.on("submit(addPolicys)",function(data){
	 		var datas=data.field;
	 		var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
	 		$.ajax({  
	            type: "POST",  
	            url:"/policys",  
	            data:JSON.stringify(datas),// 序列化表单值  
	         //   dataType: "json",
	            contentType:"application/json",
	           
	            success: function(data) { 
	            	if(data.code ==2000){
	            		 top.layer.close(index);
	            		 top.layer.msg("添加成功！");
	            		 top.layer.closeAll("iframe");
	            		 parent.location.reload();
	            	}else{
	            		top.layer.close(index);
	            		 top.layer.msg(data.msg);
	            	}
	            } ,
		 		 error: function(request) {  
		             alert("Connection error");  
		         }
	        });
	 		  return false;
	 	})
	})
	</script>
</body>
</html>

